<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('clock', function() {
    const lines = [
      'cfinteractive-23    [000] d..2  8113.233768: clock_set_rate: ' +
          'fout_apll state=500000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.249509: clock_set_rate: ' +
          'fout_apll state=300000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.289796: clock_set_rate: ' +
          'fout_apll state=400000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.294568: clock_set_rate: ' +
          'fout_apll state=500000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.309509: clock_set_rate: ' +
          'fout_apll state=800000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.388732: clock_set_rate: ' +
          'fout_apll state=200000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.410182: clock_set_rate: ' +
          'fout_apll state=300000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.414872: clock_set_rate: ' +
          'fout_apll state=600000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.494455: clock_set_rate: ' +
          'fout_apll state=200000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.515254: clock_set_rate: ' +
          'fout_apll state=500000000 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.694455: clk_set_rate: ' +
          'fout_apll 200000000',

      'cfinteractive-23    [000] d..2  8113.715254: clk_set_rate: ' +
          'fout_apll 500000000'
    ];

    const m = tr.c.TestUtils.newModelWithEvents([lines.join('\n')], {
      shiftWorldToZero: false
    });
    assert.isFalse(m.hasImportWarnings);

    const counters = m.getAllCounters();
    assert.strictEqual(counters.length, 1);

    assert.strictEqual(counters[0].series[0].samples.length, 12);
  });

  test('clock state', function() {
    const lines = [
      'cfinteractive-23    [000] d..2  8113.233768: clock_enable: ' +
          'fout_apll state=1 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.249509: clock_disable: ' +
          'fout_apll state=0 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.289796: clock_enable: ' +
          'fout_apll state=1 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.294568: clock_disable: ' +
          'fout_apll state=0 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.309509: clock_enable: ' +
          'fout_apll state=1 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.388732: clock_disable: ' +
          'fout_apll state=0 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.410182: clock_enable: ' +
          'fout_apll state=1 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.414872: clock_disable: ' +
          'fout_apll state=0 cpu_id=0',

      'cfinteractive-23    [000] d..2  8113.694455: clk_enable: ' +
          'fout_apll',

      'cfinteractive-23    [000] d..2  8113.715254: clk_disable: ' +
          'fout_apll'
    ];

    const m = tr.c.TestUtils.newModelWithEvents([lines.join('\n')], {
      shiftWorldToZero: false
    });
    assert.isFalse(m.hasImportWarnings);

    const counters = m.getAllCounters();
    assert.strictEqual(counters.length, 1);

    assert.strictEqual(counters[0].series[0].samples.length, 10);
  });
});
</script>

